﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class controls_login_AreaRelation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    //**************************************************************************************************************************8
    //该部分代码将加载省市联动下拉菜单
    //**************************************************************************************************************************8

    private void LoadProvinces()
    {
        rcbProvince.DataTextField = "ProvinceName";
        rcbProvince.DataValueField = "ID";
        rcbProvince.DataSource = xdsProvinces;

        rcbProvince.DataBind();
        //insert the first item
        rcbProvince.Items.Insert(0, new RadComboBoxItem("- 所有省份 -"));
    }

    private void LoadCites(string provinceID)
    {
        xdsCities.XPath = "/Cities/City[@PID='" + provinceID + "']";
        rcbCity.DataTextField = "CityName";
        rcbCity.DataValueField = "ID";
        rcbCity.DataSource = xdsCities;
        rcbCity.DataBind();
        rcbCity.Items.Insert(0, new RadComboBoxItem("- 所有城市 -"));
    }

    private void SelectProvince(string text)
    {
        foreach (RadComboBoxItem item in rcbProvince.Items)
        {
            if (item.Text == text)
            {
                rcbProvince.SelectedValue = item.Value;
                LoadCites(item.Value);
                break;
            }
        }
    }

    private void SelectCites(string text)
    {
        foreach (RadComboBoxItem item in rcbCity.Items)
        {
            if (item.Text == text)
            {
                rcbCity.SelectedValue = item.Value;
                break;
            }
        }
    }


    protected void rcbProvince_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        if (rcbProvince.SelectedIndex > 0)
        {
            LoadCites(e.Value);
        }
        else
        {
            rcbCity.Text = "";
            rcbCity.Items.Clear();

        }
    }

    public void InitData()
    {
        LoadProvinces();
    }

    public string SelectedCountry
    {
        get
        {
            string country = string.Empty;
            if (rcbCountry.SelectedIndex >= 0)
            {
                country = rcbCountry.SelectedItem.Text;

            }
            return country;
        }

        set
        {
            rcbCountry.SelectedIndex = 0;
        }

    }

    public string SelectedProvince
    {
        get
        {
            string province = string.Empty;
            if (rcbProvince.SelectedIndex > 0)
            {
                province = rcbProvince.SelectedItem.Text;

            }
            return province;
        }
        set
        {
            SelectProvince(value);
        }
    }


    public string SelectedCity
    {
        get
        {
            string city = string.Empty;
            if (rcbCity.SelectedIndex > 0)
            {
                city = rcbCity.SelectedItem.Text;

            }
            return city;
        }
        set
        {
            SelectCites(value);
        }
    }

}